layui.use(['form','jquery'], function () {
    var $ = layui.jquery,
        form = layui.form,
        layer = layui.layer;

    // 登录过期的时候，跳出ifram框架
    if (top.location != self.location) top.location = self.location;

    $('.bind-password').on('click', function () {
        if ($(this).hasClass('icon-5')) {
            $(this).removeClass('icon-5');
            $("input[name='password']").attr('type', 'password');
        } else {
            $(this).addClass('icon-5');
            $("input[name='password']").attr('type', 'text');
        }
    });

    $('.icon-nocheck').on('click', function () {
        if ($(this).hasClass('icon-check')) {
            $(this).removeClass('icon-check');
        } else {
            $(this).addClass('icon-check');
        }
    });

    // 进行登录操作
    form.on('submit(login)', function (data) {
        data = data.field;
        if (data.username == '') {
            layer.msg('用户名不能为空');
            return false;
        }
        if (data.password == '') {
            layer.msg('密码不能为空');
            return false;
        }
        if (data.captcha == '') {
            layer.msg('验证码不能为空');
            return false;
        }

        $.ajax({
            url:'/member/simpleLogin',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data: JSON.stringify(data),
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            contentType: "application/json",
            success:function(data){
                if (data.code == '0'){
                    layer.msg('登录成功', function () {
                        window.location = '/home/index.html';
                        window.sessionStorage.setItem("home-member",data.data);
                    });
                }else {
                    layer.msg("用户名或密码错误！",{icon:5});
                }

            }
        });


        return false;
    });
});